package vip.liux.contracts.repositories.pay;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.ListCrudRepository;
import org.springframework.data.repository.ListPagingAndSortingRepository;
import org.springframework.data.repository.NoRepositoryBean;
import vip.liux.contracts.models.pay.PayRefund;
import vip.liux.contracts.shared.enums.pay.PayRefundStatus;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

@NoRepositoryBean
public interface PayRefundRepository extends ListPagingAndSortingRepository<PayRefund, Long>, ListCrudRepository<PayRefund, Long> {
    Optional<PayRefund> findByRefundNo(String no);

    Long countByAppId(Long appId);

    Page<PayRefund> findPage(Long appId, String channelCode, String merchantOrderId, String merchantRefundId, String channelOrderNo, String channelRefundNo, PayRefundStatus status, LocalDateTime start, LocalDateTime end, Pageable page);

    PayRefund findByAppIdAndMerchantRefundId(Long id, String merchantRefundId);

    int countByAppIdAndOrderNoAndStatus(Long appId, String orderNo, PayRefundStatus payRefundStatus);

    Optional<PayRefund> findByAppIdAndRefundNo(Long appId, String refundNo);

    int updateRefundSuccess(Long id, PayRefundStatus status, LocalDateTime successTime, String channelRefundNo, PayRefundStatus updateStatus, String channelNotifyData);

    int updateRefundFailure(Long id, PayRefundStatus status, String channelRefundNo, PayRefundStatus payRefundStatus, String channelNotifyData, String channelErrorCode, String channelErrorMsg);

    List<PayRefund> findByStatus(PayRefundStatus payRefundStatus);
}